package com.neuedu.dao.impl;

import com.neuedu.common.DBUtil;
import com.neuedu.dao.BaseDao;
import com.neuedu.dao.LoginDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class LoginDaoImpl extends BaseDao implements LoginDao {
    @Override
    public int checkLogin(String username, String password) {
        Connection con = DBUtil.getCon();
        String sql = "select * from `user` where loginname=? and pass = ?";
        int flag = 0;
        try {
            PreparedStatement ps = con.prepareStatement(sql);
            ps.setString(1, username);
            ps.setString(2, password);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                flag = 1;
            }
            DBUtil.close(rs, ps, con);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return flag;
    }
}
